{include file="header/index" /}
<meta charset="UTF-8">
<style>
	.form-control {
		height: 33px;
	}
	.Role-assignment-tc{
		margin-top: 0 !important;
	}
</style>

<body>
<div class="container whitebg">
	<ul class="nav nav-tabs nav_lis" role="tablist">
        <li><i class="glyphicon glyphicon-menu-hamburger" style="margin-top: 13px;"></i></li>
        <li role="presentation" class="active tab" id="tab1" onclick="nav_lis(this)">
            <a href="#user" aria-controls="user" role="tab" data-toggle="tab">用户组管理</a>
            <span class="fr">|</span>
        </li>
        <li role="presentation" class="tab" id="tab2" onclick="nav_lis(this)">
            <a href="#admin" aria-controls="admin" class="profile" role="tab" data-toggle="tab">管理员管理</a>
            <span class="fr">|</span>
        </li>
        <li role="presentation" class="tab" id="tab3" onclick="nav_lis(this)">
            <a href="#menu" aria-controls="menu" role="tab" data-toggle="tab">系统菜单栏管理</a>
        </li>
         <li role="presentation" class="tab" id="tab4" onclick="nav_lis(this)">
            <a href="#dbbackup" aria-controls="dbbackup" role="tab" data-toggle="tab">数据库备份</a>
        </li>
         <li role="presentation" class="tab" id="tab5" onclick="nav_lis(this)">
            <a href="#dbrestore" aria-controls="dbrestore" role="tab" data-toggle="tab">数据库还原</a>
        </li>
    </ul>
    <div class="admin_nr">
        <!--用户组管理-->
        <div id="user">
             <h2 class="list-title">用户组列表</h2>
            <div class="addUser">
                <div class="row">
                    <div class="col-lg-2 col-md-2   col-sm-3">
                        <a href="{:url('Authgroup/add')}" class="btn btn-default addUser-btn">添加用户组</a>
                    </div>
                </div>
            </div>
            <div class="table-responsive mt40">
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>用户组名称</th>
                        <th>状态</th>
                        <th>添加时间</th>
                        <th>更新时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach $data as $v}
                    <tr>
                        <td>{$v.id}</td>
                        <td>{$v.title}</td>
                        <td>
                            <?php if($v['id'] != 1){?>
                            {if condition="$v['status'] eq 1"}
                            <div id="zt8" onclick="role_state(this,{$v.id})"><span class="label label-info">开启</span></div>
                            {else /}
                            <div id="zt8" onclick="role_state(this,{$v.id})"><span class="label label-danger">关闭</span></div>
                            {/if}
                            <?php }?>
                        </td>
                        <td>{:date('Y-m-d H:i:s',$v.add_time)}</td>
                        <td>{:date('Y-m-d H:i:s',$v.update_time)}</td>
                        <td>
                            <?php if($v['id'] != 1){?>
                            <a href="javascript:;"  onclick="giveQx(),authority(this)" class="btn btn-info btn-xs"  data-authority-id="{$v['id']}"> <i class="fa fa-paste"></i> 权限分配</a>&nbsp;&nbsp;
                            <a href="{:url('Authgroup/edit',array('id'=>$v['id']))}" class="btn btn-primary btn-xs"> <i class="fa fa-paste"></i> 编辑</a>&nbsp;&nbsp;
                            <!-- <a href="javascript:;" onclick="roleDel(this)" class="btn btn-danger btn-xs"> <i class="fa fa-trash-o"></i> 删除</a> -->
                            <?php }?>
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
            </div>
            <p class="fr">第1页,共1页</p>
        </div>
        <!--管理员管理-->
        <div class="hides" id="admin">
            <h2 class="list-title">管理员列表</h2>
            <div class="addUser">
                <div class="row">
                    <div class="col-lg-2 col-md-2   col-sm-3">
                        <a  href="{:url('Users/addUser')}" class="btn btn-default addUser-btn">添加用户</a>
                    </div>

                </div>
                <!-- /.row -->
            </div>

            <div class="table-responsive mt40">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>管理员名称</th>
                            <th>头像</th>
                            <th>管理员角色</th>
                            <th>登录次数</th>
                            <th>上次登录ip</th>
                            <th>上次登录时间</th>
                            <th>真实姓名</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>

                        {foreach $admin_data as $v}
                            <tr>
                                <td>{$v.id}</td>
                                <td>{$v.account}</td>
                                <td><img class="user-img" src="{:Config('IMAGES_PATH')}{$v.avatar_img}"></td>
                                <td>{$v.title}</td>
                                <td>{$v.loginnum}</td>
                                <td>{$v.last_login_ip}</td>
                                <td>{:date('Y-m-d H:i:s',$v.last_login_time)}</td>
                                <td>{$v.name}</td>
                                <td>
                                <?php if($v['is_admin'] != 1){ ?>
                                    {if condition="$v['status'] eq 1"}
                                        <div id="zt8" onclick="role_state(this,{$v.id})"><span class="label label-info">开启</span></div>
                                    {else /}
                                        <div id="zt8" onclick="role_state(this,{$v.id})"><span class="label label-danger">关闭</span></div>
                                    {/if}
                                <?php }?>
                                </td>

                                <td>
                                <?php if($v['is_admin'] != 1){ ?>
                                    <a href="{:url('Users/updateUser',array('id'=>$v['id']))}" class="btn btn-primary btn-xs"> <i class="fa fa-paste"></i> 编辑</a>&nbsp;&nbsp;
                                    <a href="javascript:;" onclick="roleDel(this,{$v.id})" class="btn btn-danger btn-xs"> <i class="fa fa-trash-o"></i> 删除</a>
                                <?php }?>
                                </td>

                            </tr>
                        {/foreach}
                    </tbody>
                </table>
            </div>
            <p class="fr">第1页,共1页</p>
        </div>
        <!--菜单栏管理-->
        <div class="hides" id="menu">
            <h2 class="list-title">菜单列表</h2>
            <div class="addUser">
                <div class="row">
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <a href="#" onclick="menuopen()" class="btn btn-default addUser-btn">添加菜单</a>
                    </div>
                    <!-- /.col-lg-6 -->
                </div>
                <!-- /.row -->
            </div>

            <div class="table-responsive mt40">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>权限名称</th>
                            <th>节点</th>
                            <th>菜单状态</th>
                            <th>添加时间</th>
                            <th>排序</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach  $menu_data as $v}
                        <tr>
                            <td>{$v.id}</td>
                            <td style='text-align:left;padding-left:{if condition="$v.leftpin neq 0"}{$v.leftpin}px{/if}'>{$v.lefthtml}{$v.title}</td>
                            <td>{$v.url}</td>
                            <td>
                                {if condition="$v['status'] eq 1"}
                                    <div id="zt8" onclick="role_state(this,{$v.id})"><span class="label label-info">开启</span></div>
                                {else /}
                                    <div id="zt8" onclick="role_state(this,{$v.id})"><span class="label label-danger">关闭</span></div>
                                {/if}

                            </td>
                            <td>{:date('Y-m-d H:i:s',$v.add_time)}</td>
                            <td><input class="t_center sort-input" type="text" value="{$v.sort}" name="sort" onchange="ModifyTheSort(this,{$v.id})"></td>
                            <td>
                                <a href="{:url('Menu/ModifyTheSort',array('id'=>$v['id']))}" class="btn btn-primary btn-xs"> <i class="fa fa-paste"></i> 编辑</a>&nbsp;&nbsp;
                                <a href="javascript:;" onclick="roleDel(this,{$v.id})" class="btn btn-danger btn-xs"> <i class="fa fa-trash-o"></i> 删除</a>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
            </div>
            <p class="fr">第1页,共1页</p>


        <div class="modal  fade in layui-layer layui-layer-page layui-layer-demo layer-anim addmenu" >
            <div class="modal-dialog ">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" onclick="menuClose()" ><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                        <h3 class="modal-title">添加菜单</h3>
                    </div>
                    <form class="form-horizontal" name="add_rule" id="add_rule" method="post" action="">
                        <div class="ibox-content">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">所属父级</label>
                                <div class="col-sm-8">
                                    <select name="pid" class="form-control" id="pid" onchange="style_display();">
                                        <option value="0">--默认顶级--</option>
                                        {foreach $menu_data as $v}
                                            <option value="{$v.id}" style="margin-left:55px;"> {$v.lefthtml}{$v.title}</option>
                                        {/foreach}

                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">菜单名称</label>
                                <div class="col-sm-8">
                                    <input type="text" name="title" id="title" placeholder="输入菜单名称" class="form-control">
                                </div>
                            </div>
                            
                            
                            <div class="hr-line-dashed" ></div>
							<div class="form-group" id="style_display">
								<label class="col-sm-3 control-label">CSS样式</label> 
								<div class="col-sm-8">
									<input type="text" name="css" id="css" placeholder="输入CSS样式" class="form-control">
									<a class="fl mt5 mr10 col-127" href="http://fontawesome.dashgame.com/" target="_blank">选择图标</a><span class="help-block m-b-none fl">如：如fa fa-user</span>
								</div>
							</div>
                            
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">节点</label>
                                <div class="col-sm-8">
                                    <input type="text" name="url" id="url" placeholder="模块/控制器/方法" class="form-control">
                                    <span class="help-block m-b-none">如：administrative/user/index (一级节点添加“#”即可)</span>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">排&nbsp;序</label>
                                <div class="col-sm-8">
                                    <input type="text" name="sort" id="sort" value="50" placeholder="输入排序" class="form-control">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">状&nbsp;态</label>
                                <div class="col-sm-6">
                                        <div class="switchery-radio" style="padding-top: 8px;">
                                            <input type="checkbox" name="status" value="1" class="js-switch" checked>
                                            默认开启
                                        </div>
                                    </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary" onclick="addMenu();"><i class="fa fa-save"></i> 保存</button>
                            <button type="button" class="btn btn-danger"  onclick="menuClose()"><i class="fa fa-close"></i> 关闭</button>
                        </div>
                    </form>
                </div>
            </div>
            </div>
        </div>
        <!--数据库备份-->
        <div class="hides" id="dbbackup">
            <p class="databaseBackup-top">
                <button class="backup" onclick="backup();">立即备份</button>
                <button class="optimization">优化表</button>
                <button class="repair">修复表</button>
            </p>
            <div class="table-responsive mt20">
            <form id="export-form" method="post" action="">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th><input type="checkbox" name="all" value="" ></th>
                            <th>表名</th>
                            <th>数据量</th>
                            <th>数据大小</th>
                            <th>创建时间</th>
                            <th>备份状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach $dbbackup_data as $k => $v}
                            <tr>
                                <td><input  type="checkbox" class="Subpage" name="ids[]" value="{$v.name}" checked="chedked"></td>
                                <td>{$v.name}</td>
                                <td>【{$v.rows}】条记录</td>
                                <td>{$v.data_length|format_bytes}</td>
                                <td>{$v.create_time}</td>
                                <td id="info">等待备份...</td>
                                <td>
                                    <button type="button" class="operatOptimi" onclick="optimizeOne('{$v.name}',this)">优化表</button>
                                    <button type="button"  class="operatRepair" onclick="repairOne('{$v.name}',this)">修复表</button>
                                </td>
                            </tr>
                        {/foreach}
                    </tbody>
                </table>
                </form>
                <p class="fr">第1页,共1页</p>
            </div>
         </div>
         <!--数据库还原-->
        <div class="hides" id="dbrestore">
            <h2 class="container-title ">数据库还原</h2>
            <div class="table-responsive mt20">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>备份名称</th>
                            <th>卷数</th>
                            <th>压缩</th>
                            <th>数据大小</th>
                            <th>备份时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>

                    {foreach $dbrestore_data as $key => $vo}
                        <tr>
                            <td>{$vo.time|date='Ymd-His',###}</td>
                            <td>{$vo.part}</td>
                            <td>{$vo.compress}</td>
                            <td>{$vo.size|format_bytes}</td>
                            <td>{$key}</td>
                            <td>
                                 <button class="operatOptimi db-import" data-time="{$vo.time}" >还原</button>
                                 <button class="operatRepair" onclick="del(this,{$vo.time})">删除</button>
                                <!-- <button class="operatOptimi" onclick="revert(this);" data-href="{:url('revert',['time'=>$vo['time']])}">还原</button> -->
                                <!-- <button class="operatRepair">删除</button> -->
                            </td>
                        </tr>
                    {/foreach}

                    </tbody>
                </table>

        </div>
    </div>


</div>

<!-- 角色分配 -->

<div class="layui-layer layui-layer-page layui-layer-demo layer-anim Role-assignment-tc hides quanxian" >
	<div class="layui-layer-title">权限分配</div>
	<div id="" class="layui-layer-content quanxian-content" style="overflow: auto;">
		<div class="left layui-layer-wrap mt20 pl10 " style="" id="">
			<input type="hidden" id="nodeid" value="">
			<h2 class="clearfix mb10"><input class="fl mt2"  type="checkbox" value="" name="allLevel" onclick="allauthority(this)" ><span class="fl">全选</span></h2>

			{foreach $rule as $key => $val}

			<div class="form-group per_class" data-id="">
				<h2 class="clearfix mb10"><input class="fl mt2"  type="checkbox"  name="oneLevel" onclick="authority(this)" value="{$val.id}"><span class="fl">{$val.title}</span></h2>
				<?php if(!empty( $val['child'])){?>
				{foreach $val['child'] as $kk => $vv}
				<div class="clearfix pl20 Two_level mb10">
					<h3 class="clearfix fl Two_level_all"><input name="tweLevel" class="fl mt2"  type="checkbox" value="{$vv.id}" onclick="twoLevel(this)"><span class="fl">{$vv.title}：</span></h3>
					<ul class="clearfix fl Three_level">
						<?php if(!empty($vv['levels'])){?>
						{foreach $vv['levels'] as $k =>$v}
						<li class="fl clearfix ml10"><input name="threeLevel" class="fl"  type="checkbox" value="{$v.id}" onclick="threeLevel(this)"><span class="fl">{$v.title}</span></li>
						{/foreach}
						<?php }?>
					</ul>
				</div>
				{/foreach}
				<?php }?>
			</div>
			{/foreach}
			<p class="authority-btn"><input type="button" value="确认分配" class="btn btn-primary" id="postform"></p>

		</div>
	</div>
	<span class="layui-layer-setwin" onclick="roleClose()">
				<a class="layui-layer-ico layui-layer-close layui-layer-close1" href="javascript:;"></a>
			</span>
	<span class="layui-layer-resize"></span>
</div>
<script type="text/javascript" src="__JS__/data2.js"></script>
<script>
    //model高度自适应
    $(document).ready(function() {
        var height = $(window).height() - 120;
        console.log(height)
        $(".quanxian").css("height", height * 0.8);
        $(".quanxian-content").css("height", height * 0.7);
        $('.quanxian').css('top','100px');
    });

    //删除
    function roleDel(obj) {
        parent.layer.alert('确认删除此条记录吗?', {
            btn: ['确认', '取消'], //按钮

        }, function() {
            parent.layer.open({
                content: '删除成功',
                time: 1
            });
            $(obj).parents("tr").remove()
        });
    }
    //状态开启关闭
    function role_state(obj,id) {
        $.post("{:url('Authgroup/updateStatus')}",{id:id},function(e){
            if(e.code == '1'){
                parent.layer.msg(e.msg, {
                    icon: 1,
                    time: 2000
                });
                if($(obj).find("span").hasClass("label-info")) {
                    $(obj).find("span").addClass("label-danger")
                    $(obj).find("span").removeClass("label-info");
                    $(obj).find("span").text("关闭");
                } else {

                    $(obj).find("span").removeClass("label-danger")
                    $(obj).find("span").addClass("label-info");
                    $(obj).find("span").text("开启")

                }
            }
        },'json')
    }
    //开启权限分配
    function giveQx(){
        $(".Role-assignment-tc").show()
    }
    //关闭权限分配
    function roleClose(){
        $(".Role-assignment-tc").hide()
    }

    //点击一级
    function allauthority(obj){
        if($(obj).is(":checked")){
            $(".per_class").find("input").prop("checked",true)
        }else{
            $(".per_class").find("input").prop("checked",false)
        }
    }


    function authority(obj){
        var inputAll=$(".per_class").find("input").length;
        if($(obj).is(":checked")){
            $(obj).parents(".per_class").find("input").prop("checked",true)
        }else{
            $(obj).parents(".per_class").find("input").prop("checked",false)
        }
        var All=0
        for(var i=0; i<inputAll;i++){
            if($(".per_class").find("input").eq(i).is(":checked")){
                All++
            }
        }
        if(All==inputAll){
            $("input[name='allLevel']").prop("checked",true)
        }else{
            $("input[name='allLevel']").prop("checked",false)
        }

    }
    //点击三级
    function twoLevel(obj){
        var tweLevel=$(obj).parents(".per_class").find("input[name='tweLevel']").length;
        var threeLevel=$(obj).parents(".per_class").find("input[name='threeLevel']").length
        var inputAll=$(".per_class").find("input").length;

        if($(obj).is(":checked")){
            $(obj).parents(".Two_level").find("input[name='threeLevel']").prop("checked",true)
            $(obj).parents(".per_class").find("input[name='oneLevel']").prop("checked",true)
        }else{
            $(obj).parents(".Two_level").find("input[name='threeLevel']").prop("checked",false)
        }



        var threeall=0
        var threenumAll=0
        //三级
        for(var j=0; j<tweLevel;j++){
            if($(obj).parents(".per_class").find("input[name='tweLevel']").eq(j).is(":checked")){
                threeall++
            }
        }
        //三级
        for(var i=0; i<inputAll;i++){
            if($(".per_class").find("input").eq(i).is(":checked")){
                threenumAll++
            }
        }

        if(threeall>0){
            $(obj).parents(".per_class").find("input[name='oneLevel']").prop("checked",true)
        }else{
            $(obj).parents(".per_class").find("input[name='oneLevel']").prop("checked",false)
        }

        if(threenumAll==inputAll){
            $("input[name='allLevel']").prop("checked",true)
        }else{
            $("input[name='allLevel']").prop("checked",false)
        }

    }
    //点击四级
    function threeLevel(obj){
        var thisArry=$(obj).parents("ul").find("li").length;
        var thisAll=$(obj).parents(".per_class").find("input[name='tweLevel']").length;
        var inputAll=$(".per_class").find("input").length;
        var count = 0;
        var count2 = 0;
        var all=0
        //循环当前三级里面的四级
        for(var i=0; i<thisArry;i++){
            if($(obj).parents("ul").find("input").is(":checked")){
                count++
            }
        }
        //循环当前三级里面的四级
        //for(var i=0; i<thisAll;i++){
        //	if($(obj).parents(".per_class").find("input[name='threeLevel']").is(":checked")){
        //		count2++
        //	}
        //}
        //循环所有的四级
        for(var i=0; i<inputAll;i++){
            if($(".per_class").find("input").eq(i).is(":checked")){
                all++
            }
        }
        //选中三级
        if(count!=0){
            $(obj).parents(".Two_level").find("input[name='tweLevel']").prop("checked",true)
        }
        //选中三级
        //if(count2!=0){
        //	$(obj).parents(".per_class").find("input[name='oneLevel']").prop("checked",true)
        //}else{
        //	$(obj).parents(".per_class").find("input[name='oneLevel']").prop("checked",false)
        //}
        //选中全选
        if(all==inputAll){
            $("input[name='allLevel']").prop("checked",true)
        }else{
            $("input[name='allLevel']").prop("checked",false)
        }
    }


    /**
     * 权限节点回选
     */

    function authority(obj){
        var id = $(obj).attr('data-authority-id');
        $('.per_class').attr('data-id',id);
        $.post("{:url('Authgroup/AjaxAuthority')}",{id:id},function(e){
            var inputObj = $('.per_class').find('input');
            $.each(e.data,function(key,val){
                $.each(inputObj,function(kk,vv){
                    if($(vv).val() == val){
                        $(vv).prop("checked",true);
                    }
                })
            })
        },'json');
    }

	/* $("#authority").click(function(){

	 });
	 */

    /**
     * 提交
     */

    $("#postform").click(function(){
        var inputObj = $('.per_class').find('input');
        var rules = [];
        $.each(inputObj,function(key,val){
            if($(val).is(':checked')){
                rules.push($(val).val());
            }
        })
        var id = $('.per_class').attr('data-id');
        $.post("{:url('Authgroup/AddRules')}",{rules:rules,id:id},function(e){
            if(e.code == 1){
                top.layer.msg(e.msg, {icon: 1,time: 2000},function(){window.location.href=e.data});
            }else{
                top.layer.msg(e.msg, {icon: 2,time: 2000});
            }
        },'json')
    })



    function nav_lis(obj){
        var lis = $(obj).index()-1;
        $(".admin_nr>div").eq(lis).show().siblings().hide()
    }
    $(function(){
         var lis = GetQueryString("type");
         $(".admin_nr>div").eq(lis-1).show().siblings().hide();
         $(".tab").removeClass("active");
         $("#tab"+lis).addClass("active");

         $(".db-import").click(function () {
             var time =$(this).attr('data-time');
             var url = "{:url('Data/revert')}?time="+time;
             var self = this, status = ".";
            parent.layer.alert('确认还原数据?', {
                btn: ['确认', '取消'],

            }, function() {
                parent.layer.msg("正在还原数据库，请不要关闭！",{
                    icon:1
                })
                    $.get(url, success, "json");
                    window.onbeforeunload = function () { return "正在还原数据库，请不要关闭！";};
                    return false;
                    function success(data) {
                        if (data.code) {
                            if (data.data.gz) {
                                data.msg += status;
                                if (status.length === 5) {
                                    status = ".";
                                } else {
                                    status += ".";
                                }
                            }
                            $(self).parent().prev().text(data.msg);
                            if (data.data.part) {
                                $.get(url, {"part": data.data.part, "start": data.data.start}, success, "json");
                            } else {
                                window.onbeforeunload = function () {return null;};
                            }
                        } else {
                            parent.layer.alert(data.msg,0);
                        }
                    }
            });
    });


    })



    function GetQueryString(name)
    {
         var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
         var r = window.location.search.substr(1).match(reg);
         if(r!=null)return  unescape(r[2]); return null;
    }
    //开启添加菜单
    function menuopen(){
        $(".addmenu").show()
    }
    //关闭添加菜单
    function menuClose(){
        $(".addmenu").hide()
    }
    //删除
    function roleDel(obj,id) {
        parent.layer.alert('确认删除此条记录吗?', {
            btn: ['确认', '取消'], //按钮

        }, function() {
            $.post("{:url('Menu/delMenu')}",{id:id},function(e){
                if(e.code == '1'){
                    parent.layer.open({content: e.msg,time: 2000});
                    $(obj).parents("tr").remove()
                }else{
                    parent.layer.open({content: e.msg,time: 2000});
                }
            },'json');
        });
    }
    //状态开启关闭
    function role_state(obj,id) {
        $.post("{:url('Menu/edit')}",{id:id},function(e){
            if(e.code == '1'){
                parent.layer.msg(e.msg, {
                    icon: 1,
                    time: 2000
                });
                if($(obj).find("span").hasClass("label-info")) {
                    $(obj).find("span").addClass("label-danger")
                    $(obj).find("span").removeClass("label-info");
                    $(obj).find("span").text("关闭");
                } else {

                    $(obj).find("span").removeClass("label-danger")
                    $(obj).find("span").addClass("label-info");
                    $(obj).find("span").text("开启")

                }
            }else{
                parent.layer.msg(e.msg,{icon:0,shade:0.1});
                return false;
            }
        },'json')



    }

    /**
     * 修改排序
     */
    function ModifyTheSort(obj,id){
        var sort = $(obj).val();
        var id = id;
        $.post("{:url('Menu/ModifyTheSort')}",{sort:sort,id:id},function(e){

        },'json');
    }


    /**
     * 添加菜单栏
     */

    function addMenu(){
        var sendData = {};
        var data = $("#add_rule").serialize(); //序列化表单

        data.split('&').forEach(function(param){
          param = param.split('=');
          sendData[param[0]]   = decodeURI(param[1]);
        })
        if($("#title").val() == ''){
            parent.layer.msg('菜单名不能为空', {icon: 2,time: 2000});
            return false;
        }

        if($("#url").val() == ''){
            parent.layer.msg('节点不能为空', {icon: 2,time: 2000});
            return false;
        }
        $.post("{:url('Menu/addMenu')}",{sendData},function(e){

            if(e.code == 0){
                layer.msg(e.msg,{icon:0,shade:0.1});
                return false;
            }

            if(e.code == '1'){
                parent.layer.msg(e.msg, {icon: 1,time: 2000},function(){window.location.href=e.data;});
            }else{
                parent.layer.msg(e.msg, {icon: 2,time: 2000});
            }
        },'json')
    }
    //数据库备份

    $("input[name='all']").click(function(){
        if($(this).is(":checked")){
            $(".Subpage").prop("checked",true)
        }else{
            $(".Subpage").prop("checked",false)
        }
    });


    //删除
    function del(obj,time){
        top.layer.confirm('你确定要删除吗?', {
              btn: ['确定','取消'] //按钮
            },function(){
                $.get("{:url('Data/del')}",{time:time},function(data){
                    if(data.code == 1){
                        $(obj).parents('tr').remove();
                        top.layer.msg(data.msg, {icon: 1});
                    }else{
                        top.layer.msg(data.msg, {icon: 2});
                    }
                },'json');
            });
    }

    
    

	/**
	 * CSS 样式展示，隐藏
	 **/
	function style_display(){
		var pid = $("#pid option:selected").val();
		if(pid != 0){
			$("#style_display").hide();
		}else{
			$("#style_display").show();
		}
	}
    



</script>

</body>

</html>